#ifndef _VIDEO_H_
#define _VIDEO_H_

#include "SDL.h"
#include "vec.hpp"
#include "mat.hpp"
#ifdef GLES
#include <EGL/egl.h>
#endif

class Image;

class Video
{
public:
	bool Open(int winwidth, int winheight, Uint32 flags);
	void Close();

	void Zoom(float zoom);
	void Resize(float w, float h);
	void ResizeToWin();
	enum
	{
		SCREWASPECT,
		KEEPASPECT
	};
	void WinResize(int winwidth, int winheight, bool keepaspect);

	void Look(float left, float top);

	void Clear();

	void Pos(float left, float top);
	void Pri(float pri);
	void Color(float red, float green, float blue, float alpha);
	void Flip(bool hori, bool vert);
	void Scale(float sx, float sy);

	enum
	{
		CLEARBOX,
		FILLBOX
	};
	void BoxDraw(float width, float height, bool fill = CLEARBOX);

	void TilesDraw(Image & img, const wchar_t *tiles, int tcols, int trows);
	void SpriteDraw(Image & img, int tile = 0);
	
	void DrawEnd();

	static const float WIDTH, HEIGHT;
	static const float PIX_PER_UNIT;
	static const float UNIT_PER_PIX;

private:
	bool WindowOpen(int winwidth, int winheight, Uint32 flags);
	
	Vec2f draw;
	float z;
	Vec2f scale;
	Box2f look;

	float r, g, b, a;
	Vec2<bool> flip;

#ifdef GLES
	EGLDisplay windisp;
	EGLSurface winsurf;
#endif
};

extern Video Vid;

#endif
